package com.tanhua.server.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.common.mapper.UserInfoMapper;
import com.tanhua.common.pojo.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

@Service
@Slf4j
public class UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * 查询用户
     * @param userid
     * @return
     */
    public UserInfo queryUserInfoByUserId(Long userid) {

        QueryWrapper<UserInfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",userid);

        UserInfo userInfo = userInfoMapper.selectOne(queryWrapper);
        return userInfo;
    }

    public List<UserInfo> queryUserInfoList(QueryWrapper<UserInfo> queryWrapper) {

        return userInfoMapper.selectList(queryWrapper);
    }


    /**
     * 根据用户id的集合查询用户列表
     *
     * @param userId
     * @return
     */
    public List<UserInfo> queryUserInfoByUserIdList(Collection<?> userId) {
        QueryWrapper<UserInfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.in("user_id",userId);

        return queryUserInfoList(queryWrapper);
    }


    /**
     * 个人信息补全
     *
     * @param userInfo
     * @return
     */
    public boolean updateUserInfoByUserId(UserInfo userInfo) {
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userInfo.getUserId());
        return this.userInfoMapper.update(userInfo, queryWrapper) > 0;
    }
}
